//
// Created by Administrator on 2021/11/23.
// May Saint Diana bless you!
//
#include <vector>
#include <iostream>
#include <string>


using namespace std;

class Solution {
public:
    int getLucky(string s, int k) {
        // 1、 转化为数字组合
        string numStr;
        for (const char &x: s) {
            numStr += to_string(int(x - 'a' + 1));
        }
        // 2、进行k次转换
        for (int i = 0; i < k; ++i) {
            int curSum = 0;
            for (char j: numStr) {
                curSum += j - '0'; // 各位求和
            }
            numStr = to_string(curSum);
        }
        return stoi(numStr);
    }

};

int main() {
    Solution solution;
    cout << solution.getLucky("zbax", 1) << endl;
    cout << solution.getLucky("iiii", 1) << endl;
    cout << solution.getLucky("leetcode", 2) << endl;
    return 0;
}
